﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.Base;
using UFIDA.U9.Base.UserRole;
using UFIDA.U9.Cust.YYD.PlugBE.Dtos;
using UFIDA.U9.Cust.YYD.PlugBE.Public;
using UFIDA.U9.SM.SO;
using UFIDA.U9.SM.SOModify;
using UFIDA.U9.SPR.SalePriceList;
using UFSoft.UBF.Business;

namespace UFIDA.U9.Cust.YYD.PlugBE.SOModifyP
{
    public class AfterUpdating : UFSoft.UBF.Eventing.IEventSubscriber
    {
        public void Notify(params object[] args)
        {
            #region 从事件参数中取得当前业务实体													 
            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            var holder = key.GetEntity() as UFIDA.U9.SM.SOModify.SOModify;
            if (holder == null)
                return;
            #endregion

            //提交传
            if (holder.OriginalData.Status == SM.SOModify.SOModifyStatusEnum.Openend && holder.Status == SM.SOModify.SOModifyStatusEnum.Approving)
            {
                //新增
                if (string.IsNullOrEmpty(holder.DescFlexField.PrivateDescSeg1))
                {
                    HttpHelper httpHelper = new HttpHelper();
                    var token = httpHelper.GetOAToken();
                    JsonConfig config = new JsonConfig();
                    httpHelper.URL = config.SelectToken("OA.URL") + "/papi/openapi/api/workflow/core/paService/v1/doCreateRequest";

                    User user = User.Finder.FindByID(Context.LoginUserID);
                    var userinfo = httpHelper.GetOAUserInfo(token, user.Code);

                    OADTO dto = new OADTO();
                    dto.access_token = token;
                    dto.userid = userinfo.Key;
                    dto.workflowId = "1198885724995141714";
                    var formData = new FormData();
                    formData.formId = "1198885724995141637";
                    var dataDetails = new List<DataDetailsItem>();



                    //申请人
                    DataDetailsItem d1 = new DataDetailsItem();
                    d1.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content = Context.LoginUser,
                        optionId = userinfo.Key,
                        type ="resource"
                    }};
                    d1.dataKey = "sqr";
                    dataDetails.Add(d1);

                    //申请部门
                    DataDetailsItem d2 = new DataDetailsItem();
                    d2.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content="",
                        optionId= userinfo.Value,
                        type="department"
                    }};
                    d2.dataKey = "sqbm";
                    dataDetails.Add(d2);

                    //推送日期
                    DataDetailsItem d3 = new DataDetailsItem();
                    d3.content = DateTime.Now.Date.ToShortDateString();
                    d3.dataKey = "tsrq";
                    dataDetails.Add(d3);

                    //变更订单号
                    DataDetailsItem d4 = new DataDetailsItem();
                    d4.content = holder.SODocNo;
                    d4.dataKey = "bgddh";
                    dataDetails.Add(d4);

                    //第几次变更
                    DataDetailsItem d5 = new DataDetailsItem();
                    d5.content = holder.ModifyCountTH.ToString();
                    d5.dataKey = "djcbg";
                    dataDetails.Add(d5);

                    //单据日期
                    DataDetailsItem d6 = new DataDetailsItem();
                    d6.content = holder.BusinessDate.ToShortDateString();
                    d6.dataKey = "djrq";
                    dataDetails.Add(d6);

                    //变更原因
                    DataDetailsItem d7 = new DataDetailsItem();
                    d7.content = holder.ModifyReason;
                    d7.dataKey = "bgyy";
                    dataDetails.Add(d7);


                    //流程编号
                    DataDetailsItem d8 = new DataDetailsItem();
                    d8.content = holder.DocNo;
                    d8.dataKey = "lcbh";
                    dataDetails.Add(d8);

                    //表头变化

                    var SOModifyLines = holder.SOModifyLines.Cast<SOModifyLine>().ToList();
                    //变更
                    DataDetailsItem h1 = new DataDetailsItem();
                    h1.content = "销售订单变更前";
                    h1.dataIndex = 1;
                    h1.dataKey = "bg";
                    h1.subFormId = "1198885892624695299";
                    dataDetails.Add(h1);

                    DataDetailsItem h2 = new DataDetailsItem();
                    h2.content = "销售订单变更后";
                    h2.dataIndex = 2;
                    h2.dataKey = "bg";
                    h2.subFormId = "1198885892624695299";
                    dataDetails.Add(h2);

                    //单据类型
                    DataDetailsItem h3 = new DataDetailsItem();
                    h3.content = holder.SO.DocumentType.Name;
                    h3.dataIndex = 1;
                    h3.dataKey = "djlx";
                    h3.subFormId = "1198885892624695299";
                    dataDetails.Add(h3);

                    DataDetailsItem h4 = new DataDetailsItem();
                    h4.content = holder.SO.DocumentType.Name;
                    h4.dataIndex = 2;
                    h4.dataKey = "djlx";
                    h4.subFormId = "1198885892624695299";
                    dataDetails.Add(h4);

                    //订货客户名称
                    DataDetailsItem h5 = new DataDetailsItem();
                    h5.content = holder.SO.OrderBy.Name;
                    h5.dataIndex = 1;
                    h5.dataKey = "gys";
                    h5.subFormId = "1198885892624695299";
                    dataDetails.Add(h5);

                    DataDetailsItem h6 = new DataDetailsItem();
                    h6.content = holder.SO.OrderBy.Name;
                    h6.dataIndex = 2;
                    h6.dataKey = "gys";
                    h6.subFormId = "1198885892624695299";
                    dataDetails.Add(h6);

                    //订货客户名称
                    DataDetailsItem h33 = new DataDetailsItem();
                    h33.content = holder.SO.ShipToSite.Name;
                    h33.dataIndex = 1;
                    h33.dataKey = "shkhmc";
                    h33.subFormId = "1198885892624695299";
                    dataDetails.Add(h33);

                    DataDetailsItem h34 = new DataDetailsItem();
                    h34.content = holder.SO.ShipToSite.Name;
                    h34.dataIndex = 2;
                    h34.dataKey = "shkhmc";
                    h34.subFormId = "1198885892624695299";
                    dataDetails.Add(h34);


                    //原币
                    DataDetailsItem h7 = new DataDetailsItem();
                    h7.content = holder.SO.TC.Name;
                    h7.dataIndex = 1;
                    h7.dataKey = "yb";
                    h7.subFormId = "1198885892624695299";
                    dataDetails.Add(h7);

                    DataDetailsItem h8 = new DataDetailsItem();
                    h8.content = holder.SO.TC.Name;
                    h8.dataIndex = 2;
                    h8.dataKey = "yb";
                    h8.subFormId = "1198885892624695299";
                    dataDetails.Add(h8);


                    //原币-核币
                    DataDetailsItem h35 = new DataDetailsItem();
                    h35.content = holder.SO.TCToACExchRateType.Name;
                    h35.dataIndex = 1;
                    h35.dataKey = "jmb";
                    h35.subFormId = "1198885892624695299";
                    dataDetails.Add(h35);

                    DataDetailsItem h36 = new DataDetailsItem();
                    h36.content = holder.SO.TCToACExchRateType.Name;
                    h36.dataIndex = 2;
                    h36.dataKey = "jmb";
                    h36.subFormId = "1198885892624695299";
                    dataDetails.Add(h36);

                    //价格含税
                    var jghs = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "IsPriceIncludeTax");
                    DataDetailsItem h9 = new DataDetailsItem();
                    h9.content = jghs == null ? (holder.SO.IsPriceIncludeTax ? "0" : "1") : (jghs.OldValue == "True" ? "0" : "1");
                    h9.dataIndex = 1;
                    h9.dataKey = "jghs";
                    h9.subFormId = "1198885892624695299";
                    dataDetails.Add(h9);

                    DataDetailsItem h10 = new DataDetailsItem();
                    h10.content = jghs == null ? (holder.SO.IsPriceIncludeTax ? "0" : "1") : (jghs.NewValue == "True" ? "0" : "1");
                    h10.dataIndex = 2;
                    h10.dataKey = "jghs";
                    h10.subFormId = "1198885892624695299";
                    dataDetails.Add(h10);

                    //税组合
                    var szh = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TaxSchedule");
                    DataDetailsItem h11 = new DataDetailsItem();
                    h11.content = szh == null ? holder.SO.TaxSchedule.Name : szh.OldName;
                    h11.dataIndex = 1;
                    h11.dataKey = "szh";
                    h11.subFormId = "1198885892624695299";
                    dataDetails.Add(h11);

                    DataDetailsItem h12 = new DataDetailsItem();
                    h12.content = szh == null ? holder.SO.TaxSchedule.Name : szh.NewName;
                    h12.dataIndex = 2;
                    h12.dataKey = "szh";
                    h12.subFormId = "1198885892624695299";
                    dataDetails.Add(h12);


                    //收货原则
                    var shyz = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "ShipRule");
                    DataDetailsItem h13 = new DataDetailsItem();
                    h13.content = shyz == null ? holder.SO.ShipRule.Name : shyz.OldName;
                    h13.dataIndex = 1;
                    h13.dataKey = "shyz";
                    h13.subFormId = "1198885892624695299";
                    dataDetails.Add(h13);

                    DataDetailsItem h14 = new DataDetailsItem();
                    h14.content = shyz == null ? holder.SO.ShipRule.Name : shyz.NewName;
                    h14.dataIndex = 2;
                    h14.dataKey = "shyz";
                    h14.subFormId = "1198885892624695299";
                    dataDetails.Add(h14);

                    //未税金额（核币）
                    var wsjehb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyAC");
                    DataDetailsItem h15 = new DataDetailsItem();
                    h15.content = wsjehb == null ? holder.SO.TotalNetMoneyAC.ToString() : wsjehb.OldValue;
                    h15.dataIndex = 1;
                    h15.dataKey = "wsjehb";
                    h15.subFormId = "1198885892624695299";
                    dataDetails.Add(h15);

                    DataDetailsItem h16 = new DataDetailsItem();
                    h16.content = wsjehb == null ? holder.SO.TotalNetMoneyAC.ToString() : wsjehb.NewValue;
                    h16.dataIndex = 2;
                    h16.dataKey = "wsjehb";
                    h16.subFormId = "1198885892624695299";
                    dataDetails.Add(h16);

                    //未税金额（本币）
                    var wsjebb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyFC");
                    DataDetailsItem h17 = new DataDetailsItem();
                    h17.content = wsjebb == null ? holder.SO.TotalNetMoneyFC.ToString() : wsjebb.OldValue;
                    h17.dataIndex = 1;
                    h17.dataKey = "jywszjebb";
                    h17.subFormId = "1198885892624695299";
                    dataDetails.Add(h17);

                    DataDetailsItem h18 = new DataDetailsItem();
                    h18.content = wsjebb == null ? holder.SO.TotalNetMoneyFC.ToString() : wsjebb.NewValue;
                    h18.dataIndex = 2;
                    h18.dataKey = "jywszjebb";
                    h18.subFormId = "1198885892624695299";
                    dataDetails.Add(h18);

                    //未税金额（原币）
                    var wsjeyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyTC");
                    DataDetailsItem h19 = new DataDetailsItem();
                    h19.content = wsjeyb == null ? holder.SO.TotalNetMoneyTC.ToString() : wsjeyb.OldValue;
                    h19.dataIndex = 1;
                    h19.dataKey = "wszjejyb";
                    h19.subFormId = "1198885892624695299";
                    dataDetails.Add(h19);

                    DataDetailsItem h20 = new DataDetailsItem();
                    h20.content = wsjeyb == null ? holder.SO.TotalNetMoneyTC.ToString() : wsjeyb.NewValue;
                    h20.dataIndex = 2;
                    h20.dataKey = "wszjejyb";
                    h20.subFormId = "1198885892624695299";
                    dataDetails.Add(h20);


                    //税额（核币）
                    var sehb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxAC");
                    DataDetailsItem h21 = new DataDetailsItem();
                    h15.content = sehb == null ? holder.SO.TotalTaxAC.ToString() : sehb.OldValue;
                    h15.dataIndex = 1;
                    h15.dataKey = "jyzsehb";
                    h15.subFormId = "1198885892624695299";
                    dataDetails.Add(h15);

                    DataDetailsItem h22 = new DataDetailsItem();
                    h16.content = sehb == null ? holder.SO.TotalTaxAC.ToString() : sehb.NewValue;
                    h16.dataIndex = 2;
                    h16.dataKey = "jyzsehb";
                    h16.subFormId = "1198885892624695299";
                    dataDetails.Add(h16);

                    //税额（本币）
                    var sebb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxFC");
                    DataDetailsItem h23 = new DataDetailsItem();
                    h23.content = sebb == null ? holder.SO.TotalTaxFC.ToString() : sebb.OldValue;
                    h23.dataIndex = 1;
                    h23.dataKey = "jyzsebb";
                    h23.subFormId = "1198885892624695299";
                    dataDetails.Add(h23);

                    DataDetailsItem h24 = new DataDetailsItem();
                    h24.content = sebb == null ? holder.SO.TotalTaxFC.ToString() : sebb.NewValue;
                    h24.dataIndex = 2;
                    h24.dataKey = "jyzsebb";
                    h24.subFormId = "1198885892624695299";
                    dataDetails.Add(h24);

                    //税额（交易币）
                    var sejyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxTC");
                    DataDetailsItem h25 = new DataDetailsItem();
                    h25.content = sejyb == null ? holder.SO.TotalTaxTC.ToString() : sejyb.OldValue;
                    h25.dataIndex = 1;
                    h25.dataKey = "sejybz";
                    h25.subFormId = "1198885892624695299";
                    dataDetails.Add(h25);

                    DataDetailsItem h26 = new DataDetailsItem();
                    h26.content = sejyb == null ? holder.SO.TotalTaxTC.ToString() : sejyb.NewValue;
                    h26.dataIndex = 2;
                    h26.dataKey = "sejybz";
                    h26.subFormId = "1198885892624695299";
                    dataDetails.Add(h26);

                    //价税合计（核币）
                    var jshjhb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC");
                    DataDetailsItem h27 = new DataDetailsItem();
                    h27.content = jshjhb == null ? holder.SO.TotalMoneyAC.ToString() : jshjhb.OldValue;
                    h27.dataIndex = 1;
                    h27.dataKey = "zjehb";
                    h27.subFormId = "1198885892624695299";
                    dataDetails.Add(h27);

                    DataDetailsItem h28 = new DataDetailsItem();
                    h28.content = jshjhb == null ? holder.SO.TotalMoneyAC.ToString() : jshjhb.NewValue;
                    h28.dataIndex = 2;
                    h28.dataKey = "zjehb";
                    h28.subFormId = "1198885892624695299";
                    dataDetails.Add(h28);

                    //价税合计（本币）
                    var jshjbb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC");
                    DataDetailsItem h29 = new DataDetailsItem();
                    h29.content = jshjbb == null ? holder.SO.TotalMoneyFC.ToString() : jshjbb.OldValue;
                    h29.dataIndex = 1;
                    h29.dataKey = "zjebb";
                    h29.subFormId = "1198885892624695299";
                    dataDetails.Add(h29);

                    DataDetailsItem h30 = new DataDetailsItem();
                    h30.content = jshjbb == null ? holder.SO.TotalMoneyFC.ToString() : jshjbb.NewValue;
                    h30.dataIndex = 2;
                    h30.dataKey = "zjebb";
                    h30.subFormId = "1198885892624695299";
                    dataDetails.Add(h30);

                    //价税合计（原币）
                    var jshjyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC");
                    DataDetailsItem h31 = new DataDetailsItem();
                    h31.content = jshjyb == null ? holder.SO.TotalMoneyTC.ToString() : jshjyb.OldValue;
                    h31.dataIndex = 1;
                    h31.dataKey = "zjejybz";
                    h31.subFormId = "1198885892624695299";
                    dataDetails.Add(h31);

                    DataDetailsItem h32 = new DataDetailsItem();
                    h32.content = jshjyb == null ? holder.SO.TotalMoneyTC.ToString() : jshjyb.NewValue;
                    h32.dataIndex = 2;
                    h32.dataKey = "zjejybz";
                    h32.subFormId = "1198885892624695299";
                    dataDetails.Add(h32);
                    //单行变化
                    int i = 1;
                    foreach (var lines in SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SOLine).GroupBy(m => m.SOLineNo))
                    {
                        SOLine sOLine = SOLine.Finder.FindByID(lines.FirstOrDefault().SOLine);

                        //变更类型
                        DataDetailsItem it11 = new DataDetailsItem();
                        it11.content = "销售订单订单行修改";
                        it11.dataIndex = 2 * i;
                        it11.dataKey = "bglx";
                        it11.subFormId = "1198887030656811008";
                        dataDetails.Add(it11);

                        DataDetailsItem it12 = new DataDetailsItem();
                        it12.content = "销售订单订单行修改";
                        it12.dataIndex = 2 * i;
                        it12.dataKey = "bglx";
                        it12.subFormId = "1198887030656811008";
                        dataDetails.Add(it12);

                        //变更
                        DataDetailsItem it21 = new DataDetailsItem();
                        it21.content = "销售订单订单行变更前";
                        it21.dataIndex = 2 * i;
                        it21.dataKey = "bg";
                        it21.subFormId = "1198887030656811008";
                        dataDetails.Add(it21);

                        DataDetailsItem it22 = new DataDetailsItem();
                        it22.content = "销售订单订单行变更后";
                        it22.dataIndex = 2 * i;
                        it22.dataKey = "bg";
                        it22.subFormId = "1198887030656811008";
                        dataDetails.Add(it22);

                        //订单行号
                        DataDetailsItem it31 = new DataDetailsItem();
                        it31.content = lines.FirstOrDefault().SOLineNo.ToString();
                        it31.dataIndex = 1 * i;
                        it31.dataKey = "ddxh";
                        it31.subFormId = "1198887030656811008";
                        dataDetails.Add(it31);

                        DataDetailsItem it32 = new DataDetailsItem();
                        it32.content = lines.FirstOrDefault().SOLineNo.ToString();
                        it32.dataIndex = 2 * i;
                        it32.dataKey = "ddxh";
                        it32.subFormId = "1198887030656811008";
                        dataDetails.Add(it32);

                        //客户料号
                        SalePriceLine salePriceLine = SalePriceLine.Finder.Find($"ItemInfo.ItemID = {sOLine.ItemInfo.ItemID.ID} and Customer = {holder.SO.OrderBy.Customer.ID} and Active = 1");
                        DataDetailsItem it41 = new DataDetailsItem();
                        it41.content = salePriceLine?.DescFlexField.PrivateDescSeg1.ToString()??"";
                        it41.dataIndex = 1 * i;
                        it41.dataKey = "khlh";
                        it41.subFormId = "1198887030656811008";
                        dataDetails.Add(it41);

                        DataDetailsItem it42 = new DataDetailsItem();
                        it42.content = salePriceLine?.DescFlexField.PrivateDescSeg1.ToString()??"";
                        it42.dataIndex = 2 * i;
                        it42.dataKey = "khlh";
                        it42.subFormId = "1198887030656811008";
                        dataDetails.Add(it42);

                        //料品
                        DataDetailsItem it51 = new DataDetailsItem();
                        it51.content = sOLine.ItemInfo.ItemID.Code.ToString();
                        it51.dataIndex = 1 * i;
                        it51.dataKey = "lp";
                        it51.subFormId = "1198887030656811008";
                        dataDetails.Add(it51);

                        DataDetailsItem it52 = new DataDetailsItem();
                        it52.content = sOLine.ItemInfo.ItemID.Code.ToString();
                        it52.dataIndex = 2 * i;
                        it52.dataKey = "lp";
                        it52.subFormId = "1198887030656811008";
                        dataDetails.Add(it52);

                        //品名
                        DataDetailsItem it61 = new DataDetailsItem();
                        it61.content = sOLine.ItemInfo.ItemID.Name.ToString();
                        it61.dataIndex = 1 * i;
                        it61.dataKey = "pm";
                        it61.subFormId = "1198887030656811008";
                        dataDetails.Add(it61);

                        DataDetailsItem it62 = new DataDetailsItem();
                        it62.content = sOLine.ItemInfo.ItemID.Name.ToString();
                        it62.dataIndex = 2 * i;
                        it62.dataKey = "pm";
                        it62.subFormId = "1198887030656811008";
                        dataDetails.Add(it62);

                        //数量
                        DataDetailsItem it71 = new DataDetailsItem();
                        it71.content = lines.FirstOrDefault(m=>m.ModifyDataItem == "OrderByQtyTU")?.OldValue ?? sOLine.OrderByQtyTU.ToString();
                        it71.dataIndex = 1 * i;
                        it71.dataKey = "sl";
                        it71.subFormId = "1198887030656811008";
                        dataDetails.Add(it71);

                        DataDetailsItem it72 = new DataDetailsItem();
                        it72.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyTU")?.NewValue  ?? sOLine.OrderByQtyTU.ToString();
                        it72.dataIndex = 2 * i;
                        it72.dataKey = "sl";
                        it72.subFormId = "1198887030656811008";
                        dataDetails.Add(it72);

                        //单位
                        DataDetailsItem it81 = new DataDetailsItem();
                        it81.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TU")?.OldName ?? sOLine.TU.Name.ToString(); 
                        it81.dataIndex = 1 * i;
                        it81.dataKey = "dw";
                        it81.subFormId = "1198887030656811008";
                        dataDetails.Add(it81);

                        DataDetailsItem it82 = new DataDetailsItem();
                        it82.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TU")?.NewName ?? sOLine.TU.Name.ToString();
                        it82.dataIndex = 2 * i;
                        it82.dataKey = "dw";
                        it82.subFormId = "1198887030656811008";
                        dataDetails.Add(it82);

                        //计价数量
                        DataDetailsItem it91 = new DataDetailsItem();
                        it91.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyPU")?.OldValue ?? sOLine.OrderByQtyPU.ToString();
                        it91.dataIndex = 1 * i;
                        it91.dataKey = "jjsl";
                        it91.subFormId = "1198887030656811008";
                        dataDetails.Add(it91);

                        DataDetailsItem it92 = new DataDetailsItem();
                        it92.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyPU")?.NewValue ?? sOLine.OrderByQtyPU.ToString();
                        it92.dataIndex = 2 * i;
                        it92.dataKey = "jjsl";
                        it92.subFormId = "1198887030656811008";
                        dataDetails.Add(it92);

                        //计价单位
                        DataDetailsItem it101 = new DataDetailsItem();
                        it101.content = lines.FirstOrDefault(m => m.ModifyDataItem == "PU")?.OldName ?? sOLine.PU.Name.ToString();
                        it101.dataIndex = 1 * i;
                        it101.dataKey = "jjdw";
                        it101.subFormId = "1198887030656811008";
                        dataDetails.Add(it101);

                        DataDetailsItem it102 = new DataDetailsItem();
                        it102.content = lines.FirstOrDefault(m => m.ModifyDataItem == "PU")?.NewName ?? sOLine.PU.Name.ToString();
                        it102.dataIndex = 2 * i;
                        it102.dataKey = "jjdw";
                        it102.subFormId = "1198887030656811008";
                        dataDetails.Add(it102);

                        //价格
                        DataDetailsItem it111 = new DataDetailsItem();
                        it111.content = lines.FirstOrDefault(m => m.ModifyDataItem == "FinallyPriceTC")?.OldValue ?? sOLine.FinallyPriceTC.ToString();
                        it111.dataIndex = 1 * i;
                        it111.dataKey = "jg";
                        it111.subFormId = "1198887030656811008";
                        dataDetails.Add(it111);

                        DataDetailsItem it122 = new DataDetailsItem();
                        it122.content = lines.FirstOrDefault(m => m.ModifyDataItem == "FinallyPriceTC")?.NewValue ?? sOLine.FinallyPriceTC.ToString();
                        it122.dataIndex = 2 * i;
                        it122.dataKey = "jg";
                        it122.subFormId = "1198887030656811008";
                        dataDetails.Add(it122);

                        //未税金额
                        DataDetailsItem it131 = new DataDetailsItem();
                        it131.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyTC")?.OldValue ?? sOLine.NetMoneyTC.ToString();
                        it131.dataIndex = 1 * i;
                        it131.dataKey = "wsje";
                        it131.subFormId = "1198887030656811008";
                        dataDetails.Add(it131);

                        DataDetailsItem it142 = new DataDetailsItem();
                        it142.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyTC")?.NewValue ?? sOLine.NetMoneyTC.ToString();
                        it142.dataIndex = 2 * i;
                        it142.dataKey = "wsje";
                        it142.subFormId = "1198887030656811008";
                        dataDetails.Add(it142);

                        //未税金额（核算币种）
                        DataDetailsItem it271 = new DataDetailsItem();
                        it271.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMontyAC")?.OldValue ?? sOLine.NetMontyAC.ToString();
                        it271.dataIndex = 1 * i;
                        it271.dataKey = "wsjehsbz";
                        it271.subFormId = "1198887030656811008";
                        dataDetails.Add(it271);

                        DataDetailsItem it282 = new DataDetailsItem();
                        it282.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMontyAC")?.NewValue ?? sOLine.NetMontyAC.ToString();
                        it282.dataIndex = 2 * i;
                        it282.dataKey = "wsjehsbz";
                        it282.subFormId = "1198887030656811008";
                        dataDetails.Add(it282);

                        //未税金额（本位币）
                        DataDetailsItem it291 = new DataDetailsItem();
                        it291.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyFC")?.OldValue ?? sOLine.NetMoneyFC.ToString();
                        it291.dataIndex = 1 * i;
                        it291.dataKey = "wsjebwb";
                        it291.subFormId = "1198887030656811008";
                        dataDetails.Add(it291);

                        DataDetailsItem it302 = new DataDetailsItem();
                        it302.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyFC")?.NewValue ?? sOLine.NetMoneyFC.ToString();
                        it302.dataIndex = 2 * i;
                        it302.dataKey = "wsjebwb";
                        it302.subFormId = "1198887030656811008";
                        dataDetails.Add(it302);

                        //税额
                        DataDetailsItem it151 = new DataDetailsItem();
                        it151.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyTC")?.OldValue ?? sOLine.TaxMoneyTC.ToString();
                        it151.dataIndex = 1 * i;
                        it151.dataKey = "se";
                        it151.subFormId = "1198887030656811008";
                        dataDetails.Add(it151);

                        DataDetailsItem it162 = new DataDetailsItem();
                        it162.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyTC")?.NewValue ?? sOLine.TaxMoneyTC.ToString();
                        it162.dataIndex = 2 * i;
                        it162.dataKey = "se";
                        it162.subFormId = "1198887030656811008";
                        dataDetails.Add(it162);

                        //税额（核算币种）
                        DataDetailsItem it231 = new DataDetailsItem();
                        it231.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyAC")?.OldValue ?? sOLine.TaxMoneyAC.ToString();
                        it231.dataIndex = 1 * i;
                        it231.dataKey = "sehsbz";
                        it231.subFormId = "1198887030656811008";
                        dataDetails.Add(it231);

                        DataDetailsItem it242 = new DataDetailsItem();
                        it242.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyAC")?.NewValue ?? sOLine.TaxMoneyAC.ToString();
                        it242.dataIndex = 2 * i;
                        it242.dataKey = "sehsbz";
                        it242.subFormId = "1198887030656811008";
                        dataDetails.Add(it242);


                        //税额（本位币）
                        DataDetailsItem it251 = new DataDetailsItem();
                        it251.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyFC")?.OldValue ?? sOLine.TaxMoneyFC.ToString();
                        it251.dataIndex = 1 * i;
                        it251.dataKey = "sebwb";
                        it251.subFormId = "1198887030656811008";
                        dataDetails.Add(it251);

                        DataDetailsItem it262 = new DataDetailsItem();
                        it262.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyFC")?.NewValue ?? sOLine.TaxMoneyFC.ToString();
                        it262.dataIndex = 2 * i;
                        it262.dataKey = "sebwb";
                        it262.subFormId = "1198887030656811008";
                        dataDetails.Add(it262);

                        //价税合计（交易币种）
                        DataDetailsItem it171 = new DataDetailsItem();
                        it171.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC")?.OldValue ?? sOLine.TotalMoneyTC.ToString();
                        it171.dataIndex = 1 * i;
                        it171.dataKey = "jshjjybz";
                        it171.subFormId = "1198887030656811008";
                        dataDetails.Add(it171);

                        DataDetailsItem it182 = new DataDetailsItem();
                        it182.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC")?.NewValue ?? sOLine.TotalMoneyTC.ToString();
                        it182.dataIndex = 2 * i;
                        it182.dataKey = "jshjjybz";
                        it182.subFormId = "1198887030656811008";
                        dataDetails.Add(it182);

                        //价税合计（本位币）
                        DataDetailsItem it191 = new DataDetailsItem();
                        it191.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC")?.OldValue ?? sOLine.TotalMoneyFC.ToString();
                        it191.dataIndex = 1 * i;
                        it191.dataKey = "jshjbwb";
                        it191.subFormId = "1198887030656811008";
                        dataDetails.Add(it191);

                        DataDetailsItem it202 = new DataDetailsItem();
                        it202.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC")?.NewValue ?? sOLine.TotalMoneyFC.ToString();
                        it202.dataIndex = 2 * i;
                        it202.dataKey = "jshjbwb";
                        it202.subFormId = "1198887030656811008";
                        dataDetails.Add(it202);

                        //价税合计（核算币种）
                        DataDetailsItem it211 = new DataDetailsItem();
                        it211.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC")?.OldValue ?? sOLine.TotalMoneyAC.ToString();
                        it211.dataIndex = 1 * i;
                        it211.dataKey = "jshjhsbz";
                        it211.subFormId = "1198887030656811008";
                        dataDetails.Add(it211);

                        DataDetailsItem it222 = new DataDetailsItem();
                        it222.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC")?.NewValue ?? sOLine.TotalMoneyAC.ToString();
                        it222.dataIndex = 2 * i;
                        it222.dataKey = "jshjhsbz";
                        it222.subFormId = "1198887030656811008";
                        dataDetails.Add(it222);



                        i++;
                    }
                    

                    formData.dataDetails = dataDetails;
                    dto.formData = formData;
                    dto.otherParams = new OtherParams { isnextflow = "1" };
                    httpHelper.Content = JsonConvert.SerializeObject(dto);
                    var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                    if (result["message"]["errmsg"].ToString() != "success")
                    {
                        throw new Exception(result["message"]["errmsg"].ToString());
                    }

                    holder.DescFlexField.PrivateDescSeg1 = result["message"]["requestId"].ToString();
                }
                else
                {
                    HttpHelper httpHelper = new HttpHelper();
                    var token = httpHelper.GetOAToken();
                    JsonConfig config = new JsonConfig();
                    httpHelper.URL = config.SelectToken("OA.URL") + "/papi/openapi/api/workflow/core/paService/v1/submitRequest";

                    User user = User.Finder.FindByID(Context.LoginUserID);
                    var userinfo = httpHelper.GetOAUserInfo(token, user.Code);

                    OAUpdateDTO dto = new OAUpdateDTO();
                    dto.access_token = token;
                    dto.userid = userinfo.Key;
                    dto.requestId = holder.DescFlexField.PrivateDescSeg1;
                    var formData = new FormData();
                    formData.formId = "1198885724995141637";
                    var dataDetails = new List<DataDetailsItem>();



                    //申请人
                    DataDetailsItem d1 = new DataDetailsItem();
                    d1.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content = Context.LoginUser,
                        optionId = userinfo.Key,
                        type ="resource"
                    }};
                    d1.dataKey = "sqr";
                    dataDetails.Add(d1);

                    //申请部门
                    DataDetailsItem d2 = new DataDetailsItem();
                    d2.dataOptions = new List<DataOptionsItem> {new DataOptionsItem{
                        content="",
                        optionId= userinfo.Value,
                        type="department"
                    }};
                    d2.dataKey = "sqbm";
                    dataDetails.Add(d2);

                    //推送日期
                    DataDetailsItem d3 = new DataDetailsItem();
                    d3.content = DateTime.Now.Date.ToShortDateString();
                    d3.dataKey = "tsrq";
                    dataDetails.Add(d3);

                    //变更订单号
                    DataDetailsItem d4 = new DataDetailsItem();
                    d4.content = holder.SODocNo;
                    d4.dataKey = "bgddh";
                    dataDetails.Add(d4);

                    //第几次变更
                    DataDetailsItem d5 = new DataDetailsItem();
                    d5.content = holder.ModifyCountTH.ToString();
                    d5.dataKey = "djcbg";
                    dataDetails.Add(d5);

                    //单据日期
                    DataDetailsItem d6 = new DataDetailsItem();
                    d6.content = holder.BusinessDate.ToShortDateString();
                    d6.dataKey = "djrq";
                    dataDetails.Add(d6);

                    //变更原因
                    DataDetailsItem d7 = new DataDetailsItem();
                    d7.content = holder.ModifyReason;
                    d7.dataKey = "bgyy";
                    dataDetails.Add(d7);


                    //流程编号
                    DataDetailsItem d8 = new DataDetailsItem();
                    d8.content = holder.DocNo;
                    d8.dataKey = "lcbh";
                    dataDetails.Add(d8);

                    //表头变化

                    var SOModifyLines = holder.SOModifyLines.Cast<SOModifyLine>().ToList();
                    //变更
                    DataDetailsItem h1 = new DataDetailsItem();
                    h1.content = "销售订单变更前";
                    h1.dataIndex = 1;
                    h1.dataKey = "bg";
                    h1.subFormId = "1198885892624695299";
                    dataDetails.Add(h1);

                    DataDetailsItem h2 = new DataDetailsItem();
                    h2.content = "销售订单变更后";
                    h2.dataIndex = 2;
                    h2.dataKey = "bg";
                    h2.subFormId = "1198885892624695299";
                    dataDetails.Add(h2);

                    //单据类型
                    DataDetailsItem h3 = new DataDetailsItem();
                    h3.content = holder.SO.DocumentType.Name;
                    h3.dataIndex = 1;
                    h3.dataKey = "djlx";
                    h3.subFormId = "1198885892624695299";
                    dataDetails.Add(h3);

                    DataDetailsItem h4 = new DataDetailsItem();
                    h4.content = holder.SO.DocumentType.Name;
                    h4.dataIndex = 2;
                    h4.dataKey = "djlx";
                    h4.subFormId = "1198885892624695299";
                    dataDetails.Add(h4);

                    //订货客户名称
                    DataDetailsItem h5 = new DataDetailsItem();
                    h5.content = holder.SO.OrderBy.Name;
                    h5.dataIndex = 1;
                    h5.dataKey = "gys";
                    h5.subFormId = "1198885892624695299";
                    dataDetails.Add(h5);

                    DataDetailsItem h6 = new DataDetailsItem();
                    h6.content = holder.SO.OrderBy.Name;
                    h6.dataIndex = 2;
                    h6.dataKey = "gys";
                    h6.subFormId = "1198885892624695299";
                    dataDetails.Add(h6);

                    //订货客户名称
                    DataDetailsItem h33 = new DataDetailsItem();
                    h33.content = holder.SO.ShipToSite.Name;
                    h33.dataIndex = 1;
                    h33.dataKey = "shkhmc";
                    h33.subFormId = "1198885892624695299";
                    dataDetails.Add(h33);

                    DataDetailsItem h34 = new DataDetailsItem();
                    h34.content = holder.SO.ShipToSite.Name;
                    h34.dataIndex = 2;
                    h34.dataKey = "shkhmc";
                    h34.subFormId = "1198885892624695299";
                    dataDetails.Add(h34);


                    //原币
                    DataDetailsItem h7 = new DataDetailsItem();
                    h7.content = holder.SO.TC.Name;
                    h7.dataIndex = 1;
                    h7.dataKey = "yb";
                    h7.subFormId = "1198885892624695299";
                    dataDetails.Add(h7);

                    DataDetailsItem h8 = new DataDetailsItem();
                    h8.content = holder.SO.TC.Name;
                    h8.dataIndex = 2;
                    h8.dataKey = "yb";
                    h8.subFormId = "1198885892624695299";
                    dataDetails.Add(h8);


                    //原币-核币
                    DataDetailsItem h35 = new DataDetailsItem();
                    h35.content = holder.SO.TCToACExchRateType.Name;
                    h35.dataIndex = 1;
                    h35.dataKey = "jmb";
                    h35.subFormId = "1198885892624695299";
                    dataDetails.Add(h35);

                    DataDetailsItem h36 = new DataDetailsItem();
                    h36.content = holder.SO.TCToACExchRateType.Name;
                    h36.dataIndex = 2;
                    h36.dataKey = "jmb";
                    h36.subFormId = "1198885892624695299";
                    dataDetails.Add(h36);

                    //价格含税
                    var jghs = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "IsPriceIncludeTax");
                    DataDetailsItem h9 = new DataDetailsItem();
                    h9.content = jghs == null ? (holder.SO.IsPriceIncludeTax ? "0" : "1") : (jghs.OldValue == "True" ? "0" : "1");
                    h9.dataIndex = 1;
                    h9.dataKey = "jghs";
                    h9.subFormId = "1198885892624695299";
                    dataDetails.Add(h9);

                    DataDetailsItem h10 = new DataDetailsItem();
                    h10.content = jghs == null ? (holder.SO.IsPriceIncludeTax ? "0" : "1") : (jghs.NewValue == "True" ? "0" : "1");
                    h10.dataIndex = 2;
                    h10.dataKey = "jghs";
                    h10.subFormId = "1198885892624695299";
                    dataDetails.Add(h10);

                    //税组合
                    var szh = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TaxSchedule");
                    DataDetailsItem h11 = new DataDetailsItem();
                    h11.content = szh == null ? holder.SO.TaxSchedule.Name : szh.OldName;
                    h11.dataIndex = 1;
                    h11.dataKey = "szh";
                    h11.subFormId = "1198885892624695299";
                    dataDetails.Add(h11);

                    DataDetailsItem h12 = new DataDetailsItem();
                    h12.content = szh == null ? holder.SO.TaxSchedule.Name : szh.NewName;
                    h12.dataIndex = 2;
                    h12.dataKey = "szh";
                    h12.subFormId = "1198885892624695299";
                    dataDetails.Add(h12);


                    //收货原则
                    var shyz = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "ShipRule");
                    DataDetailsItem h13 = new DataDetailsItem();
                    h13.content = shyz == null ? holder.SO.ShipRule.Name : shyz.OldName;
                    h13.dataIndex = 1;
                    h13.dataKey = "shyz";
                    h13.subFormId = "1198885892624695299";
                    dataDetails.Add(h13);

                    DataDetailsItem h14 = new DataDetailsItem();
                    h14.content = shyz == null ? holder.SO.ShipRule.Name : shyz.NewName;
                    h14.dataIndex = 2;
                    h14.dataKey = "shyz";
                    h14.subFormId = "1198885892624695299";
                    dataDetails.Add(h14);

                    //未税金额（核币）
                    var wsjehb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyAC");
                    DataDetailsItem h15 = new DataDetailsItem();
                    h15.content = wsjehb == null ? holder.SO.TotalNetMoneyAC.ToString() : wsjehb.OldValue;
                    h15.dataIndex = 1;
                    h15.dataKey = "wsjehb";
                    h15.subFormId = "1198885892624695299";
                    dataDetails.Add(h15);

                    DataDetailsItem h16 = new DataDetailsItem();
                    h16.content = wsjehb == null ? holder.SO.TotalNetMoneyAC.ToString() : wsjehb.NewValue;
                    h16.dataIndex = 2;
                    h16.dataKey = "wsjehb";
                    h16.subFormId = "1198885892624695299";
                    dataDetails.Add(h16);

                    //未税金额（本币）
                    var wsjebb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyFC");
                    DataDetailsItem h17 = new DataDetailsItem();
                    h17.content = wsjebb == null ? holder.SO.TotalNetMoneyFC.ToString() : wsjebb.OldValue;
                    h17.dataIndex = 1;
                    h17.dataKey = "jywszjebb";
                    h17.subFormId = "1198885892624695299";
                    dataDetails.Add(h17);

                    DataDetailsItem h18 = new DataDetailsItem();
                    h18.content = wsjebb == null ? holder.SO.TotalNetMoneyFC.ToString() : wsjebb.NewValue;
                    h18.dataIndex = 2;
                    h18.dataKey = "jywszjebb";
                    h18.subFormId = "1198885892624695299";
                    dataDetails.Add(h18);

                    //未税金额（原币）
                    var wsjeyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalNetMoneyTC");
                    DataDetailsItem h19 = new DataDetailsItem();
                    h19.content = wsjeyb == null ? holder.SO.TotalNetMoneyTC.ToString() : wsjeyb.OldValue;
                    h19.dataIndex = 1;
                    h19.dataKey = "wszjejyb";
                    h19.subFormId = "1198885892624695299";
                    dataDetails.Add(h19);

                    DataDetailsItem h20 = new DataDetailsItem();
                    h20.content = wsjeyb == null ? holder.SO.TotalNetMoneyTC.ToString() : wsjeyb.NewValue;
                    h20.dataIndex = 2;
                    h20.dataKey = "wszjejyb";
                    h20.subFormId = "1198885892624695299";
                    dataDetails.Add(h20);


                    //税额（核币）
                    var sehb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxAC");
                    DataDetailsItem h21 = new DataDetailsItem();
                    h15.content = sehb == null ? holder.SO.TotalTaxAC.ToString() : sehb.OldValue;
                    h15.dataIndex = 1;
                    h15.dataKey = "jyzsehb";
                    h15.subFormId = "1198885892624695299";
                    dataDetails.Add(h15);

                    DataDetailsItem h22 = new DataDetailsItem();
                    h16.content = sehb == null ? holder.SO.TotalTaxAC.ToString() : sehb.NewValue;
                    h16.dataIndex = 2;
                    h16.dataKey = "jyzsehb";
                    h16.subFormId = "1198885892624695299";
                    dataDetails.Add(h16);

                    //税额（本币）
                    var sebb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxFC");
                    DataDetailsItem h23 = new DataDetailsItem();
                    h23.content = sebb == null ? holder.SO.TotalTaxFC.ToString() : sebb.OldValue;
                    h23.dataIndex = 1;
                    h23.dataKey = "jyzsebb";
                    h23.subFormId = "1198885892624695299";
                    dataDetails.Add(h23);

                    DataDetailsItem h24 = new DataDetailsItem();
                    h24.content = sebb == null ? holder.SO.TotalTaxFC.ToString() : sebb.NewValue;
                    h24.dataIndex = 2;
                    h24.dataKey = "jyzsebb";
                    h24.subFormId = "1198885892624695299";
                    dataDetails.Add(h24);

                    //税额（交易币）
                    var sejyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalTaxTC");
                    DataDetailsItem h25 = new DataDetailsItem();
                    h25.content = sejyb == null ? holder.SO.TotalTaxTC.ToString() : sejyb.OldValue;
                    h25.dataIndex = 1;
                    h25.dataKey = "sejybz";
                    h25.subFormId = "1198885892624695299";
                    dataDetails.Add(h25);

                    DataDetailsItem h26 = new DataDetailsItem();
                    h26.content = sejyb == null ? holder.SO.TotalTaxTC.ToString() : sejyb.NewValue;
                    h26.dataIndex = 2;
                    h26.dataKey = "sejybz";
                    h26.subFormId = "1198885892624695299";
                    dataDetails.Add(h26);

                    //价税合计（核币）
                    var jshjhb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC");
                    DataDetailsItem h27 = new DataDetailsItem();
                    h27.content = jshjhb == null ? holder.SO.TotalMoneyAC.ToString() : jshjhb.OldValue;
                    h27.dataIndex = 1;
                    h27.dataKey = "zjehb";
                    h27.subFormId = "1198885892624695299";
                    dataDetails.Add(h27);

                    DataDetailsItem h28 = new DataDetailsItem();
                    h28.content = jshjhb == null ? holder.SO.TotalMoneyAC.ToString() : jshjhb.NewValue;
                    h28.dataIndex = 2;
                    h28.dataKey = "zjehb";
                    h28.subFormId = "1198885892624695299";
                    dataDetails.Add(h28);

                    //价税合计（本币）
                    var jshjbb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC");
                    DataDetailsItem h29 = new DataDetailsItem();
                    h29.content = jshjbb == null ? holder.SO.TotalMoneyFC.ToString() : jshjbb.OldValue;
                    h29.dataIndex = 1;
                    h29.dataKey = "zjebb";
                    h29.subFormId = "1198885892624695299";
                    dataDetails.Add(h29);

                    DataDetailsItem h30 = new DataDetailsItem();
                    h30.content = jshjbb == null ? holder.SO.TotalMoneyFC.ToString() : jshjbb.NewValue;
                    h30.dataIndex = 2;
                    h30.dataKey = "zjebb";
                    h30.subFormId = "1198885892624695299";
                    dataDetails.Add(h30);

                    //价税合计（原币）
                    var jshjyb = SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SO).FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC");
                    DataDetailsItem h31 = new DataDetailsItem();
                    h31.content = jshjyb == null ? holder.SO.TotalMoneyTC.ToString() : jshjyb.OldValue;
                    h31.dataIndex = 1;
                    h31.dataKey = "zjejybz";
                    h31.subFormId = "1198885892624695299";
                    dataDetails.Add(h31);

                    DataDetailsItem h32 = new DataDetailsItem();
                    h32.content = jshjyb == null ? holder.SO.TotalMoneyTC.ToString() : jshjyb.NewValue;
                    h32.dataIndex = 2;
                    h32.dataKey = "zjejybz";
                    h32.subFormId = "1198885892624695299";
                    dataDetails.Add(h32);
                    //单行变化
                    int i = 1;
                    foreach (var lines in SOModifyLines.Where(m => m.SOModifyType == SOModifyTypeEnum.SOLine).GroupBy(m => m.SOLineNo))
                    {
                        SOLine sOLine = SOLine.Finder.FindByID(lines.FirstOrDefault().SOLine);

                        //变更类型
                        DataDetailsItem it11 = new DataDetailsItem();
                        it11.content = "销售订单订单行修改";
                        it11.dataIndex = 2 * i;
                        it11.dataKey = "bglx";
                        it11.subFormId = "1198887030656811008";
                        dataDetails.Add(it11);

                        DataDetailsItem it12 = new DataDetailsItem();
                        it12.content = "销售订单订单行修改";
                        it12.dataIndex = 2 * i;
                        it12.dataKey = "bglx";
                        it12.subFormId = "1198887030656811008";
                        dataDetails.Add(it12);

                        //变更
                        DataDetailsItem it21 = new DataDetailsItem();
                        it21.content = "销售订单订单行变更前";
                        it21.dataIndex = 2 * i;
                        it21.dataKey = "bg";
                        it21.subFormId = "1198887030656811008";
                        dataDetails.Add(it21);

                        DataDetailsItem it22 = new DataDetailsItem();
                        it22.content = "销售订单订单行变更后";
                        it22.dataIndex = 2 * i;
                        it22.dataKey = "bg";
                        it22.subFormId = "1198887030656811008";
                        dataDetails.Add(it22);

                        //订单行号
                        DataDetailsItem it31 = new DataDetailsItem();
                        it31.content = lines.FirstOrDefault().SOLineNo.ToString();
                        it31.dataIndex = 1 * i;
                        it31.dataKey = "ddxh";
                        it31.subFormId = "1198887030656811008";
                        dataDetails.Add(it31);

                        DataDetailsItem it32 = new DataDetailsItem();
                        it32.content = lines.FirstOrDefault().SOLineNo.ToString();
                        it32.dataIndex = 2 * i;
                        it32.dataKey = "ddxh";
                        it32.subFormId = "1198887030656811008";
                        dataDetails.Add(it32);

                        //客户料号
                        SalePriceLine salePriceLine = SalePriceLine.Finder.Find($"ItemInfo.ItemID = {sOLine.ItemInfo.ItemID.ID} and Customer = {holder.SO.OrderBy.Customer.ID} and Active = 1");
                        DataDetailsItem it41 = new DataDetailsItem();
                        it41.content = salePriceLine?.DescFlexField.PrivateDescSeg1.ToString() ?? "";
                        it41.dataIndex = 1 * i;
                        it41.dataKey = "khlh";
                        it41.subFormId = "1198887030656811008";
                        dataDetails.Add(it41);

                        DataDetailsItem it42 = new DataDetailsItem();
                        it42.content = salePriceLine?.DescFlexField.PrivateDescSeg1.ToString() ?? "";
                        it42.dataIndex = 2 * i;
                        it42.dataKey = "khlh";
                        it42.subFormId = "1198887030656811008";
                        dataDetails.Add(it42);

                        //料品
                        DataDetailsItem it51 = new DataDetailsItem();
                        it51.content = sOLine.ItemInfo.ItemID.Code.ToString();
                        it51.dataIndex = 1 * i;
                        it51.dataKey = "lp";
                        it51.subFormId = "1198887030656811008";
                        dataDetails.Add(it51);

                        DataDetailsItem it52 = new DataDetailsItem();
                        it52.content = sOLine.ItemInfo.ItemID.Code.ToString();
                        it52.dataIndex = 2 * i;
                        it52.dataKey = "lp";
                        it52.subFormId = "1198887030656811008";
                        dataDetails.Add(it52);

                        //品名
                        DataDetailsItem it61 = new DataDetailsItem();
                        it61.content = sOLine.ItemInfo.ItemID.Name.ToString();
                        it61.dataIndex = 1 * i;
                        it61.dataKey = "pm";
                        it61.subFormId = "1198887030656811008";
                        dataDetails.Add(it61);

                        DataDetailsItem it62 = new DataDetailsItem();
                        it62.content = sOLine.ItemInfo.ItemID.Name.ToString();
                        it62.dataIndex = 2 * i;
                        it62.dataKey = "pm";
                        it62.subFormId = "1198887030656811008";
                        dataDetails.Add(it62);

                        //数量
                        DataDetailsItem it71 = new DataDetailsItem();
                        it71.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyTU")?.OldValue ?? sOLine.OrderByQtyTU.ToString();
                        it71.dataIndex = 1 * i;
                        it71.dataKey = "sl";
                        it71.subFormId = "1198887030656811008";
                        dataDetails.Add(it71);

                        DataDetailsItem it72 = new DataDetailsItem();
                        it72.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyTU")?.NewValue ?? sOLine.OrderByQtyTU.ToString();
                        it72.dataIndex = 2 * i;
                        it72.dataKey = "sl";
                        it72.subFormId = "1198887030656811008";
                        dataDetails.Add(it72);

                        //单位
                        DataDetailsItem it81 = new DataDetailsItem();
                        it81.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TU")?.OldName ?? sOLine.TU.Name.ToString();
                        it81.dataIndex = 1 * i;
                        it81.dataKey = "dw";
                        it81.subFormId = "1198887030656811008";
                        dataDetails.Add(it81);

                        DataDetailsItem it82 = new DataDetailsItem();
                        it82.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TU")?.NewName ?? sOLine.TU.Name.ToString();
                        it82.dataIndex = 2 * i;
                        it82.dataKey = "dw";
                        it82.subFormId = "1198887030656811008";
                        dataDetails.Add(it82);

                        //计价数量
                        DataDetailsItem it91 = new DataDetailsItem();
                        it91.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyPU")?.OldValue ?? sOLine.OrderByQtyPU.ToString();
                        it91.dataIndex = 1 * i;
                        it91.dataKey = "jjsl";
                        it91.subFormId = "1198887030656811008";
                        dataDetails.Add(it91);

                        DataDetailsItem it92 = new DataDetailsItem();
                        it92.content = lines.FirstOrDefault(m => m.ModifyDataItem == "OrderByQtyPU")?.NewValue ?? sOLine.OrderByQtyPU.ToString();
                        it92.dataIndex = 2 * i;
                        it92.dataKey = "jjsl";
                        it92.subFormId = "1198887030656811008";
                        dataDetails.Add(it92);

                        //计价单位
                        DataDetailsItem it101 = new DataDetailsItem();
                        it101.content = lines.FirstOrDefault(m => m.ModifyDataItem == "PU")?.OldName ?? sOLine.PU.Name.ToString();
                        it101.dataIndex = 1 * i;
                        it101.dataKey = "jjdw";
                        it101.subFormId = "1198887030656811008";
                        dataDetails.Add(it101);

                        DataDetailsItem it102 = new DataDetailsItem();
                        it102.content = lines.FirstOrDefault(m => m.ModifyDataItem == "PU")?.NewName ?? sOLine.PU.Name.ToString();
                        it102.dataIndex = 2 * i;
                        it102.dataKey = "jjdw";
                        it102.subFormId = "1198887030656811008";
                        dataDetails.Add(it102);

                        //价格
                        DataDetailsItem it111 = new DataDetailsItem();
                        it111.content = lines.FirstOrDefault(m => m.ModifyDataItem == "FinallyPriceTC")?.OldValue ?? sOLine.FinallyPriceTC.ToString();
                        it111.dataIndex = 1 * i;
                        it111.dataKey = "jg";
                        it111.subFormId = "1198887030656811008";
                        dataDetails.Add(it111);

                        DataDetailsItem it122 = new DataDetailsItem();
                        it122.content = lines.FirstOrDefault(m => m.ModifyDataItem == "FinallyPriceTC")?.NewValue ?? sOLine.FinallyPriceTC.ToString();
                        it122.dataIndex = 2 * i;
                        it122.dataKey = "jg";
                        it122.subFormId = "1198887030656811008";
                        dataDetails.Add(it122);

                        //未税金额
                        DataDetailsItem it131 = new DataDetailsItem();
                        it131.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyTC")?.OldValue ?? sOLine.NetMoneyTC.ToString();
                        it131.dataIndex = 1 * i;
                        it131.dataKey = "wsje";
                        it131.subFormId = "1198887030656811008";
                        dataDetails.Add(it131);

                        DataDetailsItem it142 = new DataDetailsItem();
                        it142.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyTC")?.NewValue ?? sOLine.NetMoneyTC.ToString();
                        it142.dataIndex = 2 * i;
                        it142.dataKey = "wsje";
                        it142.subFormId = "1198887030656811008";
                        dataDetails.Add(it142);

                        //未税金额（核算币种）
                        DataDetailsItem it271 = new DataDetailsItem();
                        it271.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMontyAC")?.OldValue ?? sOLine.NetMontyAC.ToString();
                        it271.dataIndex = 1 * i;
                        it271.dataKey = "wsjehsbz";
                        it271.subFormId = "1198887030656811008";
                        dataDetails.Add(it271);

                        DataDetailsItem it282 = new DataDetailsItem();
                        it282.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMontyAC")?.NewValue ?? sOLine.NetMontyAC.ToString();
                        it282.dataIndex = 2 * i;
                        it282.dataKey = "wsjehsbz";
                        it282.subFormId = "1198887030656811008";
                        dataDetails.Add(it282);

                        //未税金额（本位币）
                        DataDetailsItem it291 = new DataDetailsItem();
                        it291.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyFC")?.OldValue ?? sOLine.NetMoneyFC.ToString();
                        it291.dataIndex = 1 * i;
                        it291.dataKey = "wsjebwb";
                        it291.subFormId = "1198887030656811008";
                        dataDetails.Add(it291);

                        DataDetailsItem it302 = new DataDetailsItem();
                        it302.content = lines.FirstOrDefault(m => m.ModifyDataItem == "NetMoneyFC")?.NewValue ?? sOLine.NetMoneyFC.ToString();
                        it302.dataIndex = 2 * i;
                        it302.dataKey = "wsjebwb";
                        it302.subFormId = "1198887030656811008";
                        dataDetails.Add(it302);

                        //税额
                        DataDetailsItem it151 = new DataDetailsItem();
                        it151.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyTC")?.OldValue ?? sOLine.TaxMoneyTC.ToString();
                        it151.dataIndex = 1 * i;
                        it151.dataKey = "se";
                        it151.subFormId = "1198887030656811008";
                        dataDetails.Add(it151);

                        DataDetailsItem it162 = new DataDetailsItem();
                        it162.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyTC")?.NewValue ?? sOLine.TaxMoneyTC.ToString();
                        it162.dataIndex = 2 * i;
                        it162.dataKey = "se";
                        it162.subFormId = "1198887030656811008";
                        dataDetails.Add(it162);

                        //税额（核算币种）
                        DataDetailsItem it231 = new DataDetailsItem();
                        it231.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyAC")?.OldValue ?? sOLine.TaxMoneyAC.ToString();
                        it231.dataIndex = 1 * i;
                        it231.dataKey = "sehsbz";
                        it231.subFormId = "1198887030656811008";
                        dataDetails.Add(it231);

                        DataDetailsItem it242 = new DataDetailsItem();
                        it242.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyAC")?.NewValue ?? sOLine.TaxMoneyAC.ToString();
                        it242.dataIndex = 2 * i;
                        it242.dataKey = "sehsbz";
                        it242.subFormId = "1198887030656811008";
                        dataDetails.Add(it242);


                        //税额（本位币）
                        DataDetailsItem it251 = new DataDetailsItem();
                        it251.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyFC")?.OldValue ?? sOLine.TaxMoneyFC.ToString();
                        it251.dataIndex = 1 * i;
                        it251.dataKey = "sebwb";
                        it251.subFormId = "1198887030656811008";
                        dataDetails.Add(it251);

                        DataDetailsItem it262 = new DataDetailsItem();
                        it262.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TaxMoneyFC")?.NewValue ?? sOLine.TaxMoneyFC.ToString();
                        it262.dataIndex = 2 * i;
                        it262.dataKey = "sebwb";
                        it262.subFormId = "1198887030656811008";
                        dataDetails.Add(it262);

                        //价税合计（交易币种）
                        DataDetailsItem it171 = new DataDetailsItem();
                        it171.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC")?.OldValue ?? sOLine.TotalMoneyTC.ToString();
                        it171.dataIndex = 1 * i;
                        it171.dataKey = "jshjjybz";
                        it171.subFormId = "1198887030656811008";
                        dataDetails.Add(it171);

                        DataDetailsItem it182 = new DataDetailsItem();
                        it182.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyTC")?.NewValue ?? sOLine.TotalMoneyTC.ToString();
                        it182.dataIndex = 2 * i;
                        it182.dataKey = "jshjjybz";
                        it182.subFormId = "1198887030656811008";
                        dataDetails.Add(it182);

                        //价税合计（本位币）
                        DataDetailsItem it191 = new DataDetailsItem();
                        it191.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC")?.OldValue ?? sOLine.TotalMoneyFC.ToString();
                        it191.dataIndex = 1 * i;
                        it191.dataKey = "jshjbwb";
                        it191.subFormId = "1198887030656811008";
                        dataDetails.Add(it191);

                        DataDetailsItem it202 = new DataDetailsItem();
                        it202.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyFC")?.NewValue ?? sOLine.TotalMoneyFC.ToString();
                        it202.dataIndex = 2 * i;
                        it202.dataKey = "jshjbwb";
                        it202.subFormId = "1198887030656811008";
                        dataDetails.Add(it202);

                        //价税合计（核算币种）
                        DataDetailsItem it211 = new DataDetailsItem();
                        it211.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC")?.OldValue ?? sOLine.TotalMoneyAC.ToString();
                        it211.dataIndex = 1 * i;
                        it211.dataKey = "jshjhsbz";
                        it211.subFormId = "1198887030656811008";
                        dataDetails.Add(it211);

                        DataDetailsItem it222 = new DataDetailsItem();
                        it222.content = lines.FirstOrDefault(m => m.ModifyDataItem == "TotalMoneyAC")?.NewValue ?? sOLine.TotalMoneyAC.ToString();
                        it222.dataIndex = 2 * i;
                        it222.dataKey = "jshjhsbz";
                        it222.subFormId = "1198887030656811008";
                        dataDetails.Add(it222);



                        i++;
                    }


                    formData.dataDetails = dataDetails;
                    dto.formData = formData;
                    var Content = JsonConvert.SerializeObject(dto);
                    httpHelper.Content = Content.Remove(Content.Length - 2, 2) + @" },""seniorFormParam"": {""subFormMatchFields"": { ""1198887030656811008"": {""cover"": true,""subFormMatchMore"": ""ZERO"",""subFormNoMatch"": ""ADD""}}}, ""isNewFormData"": true}";
                    var result = JObject.Parse(httpHelper.HttpPosts("POST"));
                    if (result["message"]["errmsg"].ToString() != "success")
                    {
                        throw new Exception(result["message"]["errmsg"].ToString());
                    }
                }
              
            }
        }
    }
}
